Skip to content

perf(variant): build BinaryView arrays directly - #10640

Merged
Jefffrey merged 3 commits into
apache:mainfrom
cakeni:perf/variant-builder-finalization
Aug 22, 2026
Merged

perf(variant): build BinaryView arrays directly#10640
Jefffrey merged 3 commits into
apache:mainfrom
cakeni:perf/variant-builder-finalization

Conversation

@cakeni

@cakeni cakeni commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Finalizing VariantArrayBuilder replayed every offset through BinaryViewBuilder::try_append_view, repeating bounds and value validation for buffers and offsets produced internally by the Variant builders.

What changes are included in this PR?

  • Add a focused Criterion benchmark that times only build() for 262,144 small values.
  • Construct views directly from the recorded offset slices.
  • Build the final BinaryViewArray from those validated views, with the safety invariants documented at the unchecked constructor.

Are these changes tested?

  • cargo +stable-x86_64-pc-windows-gnu test -p parquet-variant-compute --lib (347 passed)
  • cargo +stable-x86_64-pc-windows-gnu bench -p parquet-variant-compute --bench variant_kernels -- variant_array_builder_build_262k_small_values --noplot
    • Before: [2.9213 ms, 2.9390 ms, 2.9577 ms]
    • After: [2.0393 ms, 2.0538 ms, 2.0689 ms]
    • Criterion change: [-30.816%, -30.118%, -29.428%], p = 0.00
  • cargo fmt --all -- --check
  • git diff --check

Are there any user-facing changes?

No API or behavior changes. VariantArrayBuilder::build is approximately 30% faster in the focused many-small-values benchmark.

AI assistance

I identified and evaluated this optimization, chose the final approach, and reviewed and refined the implementation and benchmark. OpenAI Codex assisted with code exploration, drafting, and benchmark preparation.

@github-actions github-actions Bot added the parquet-variant parquet-variant* crates label Aug 11, 2026
builder
.try_append_view(block, start, end - start)
.expect("Failed to append view");
views.push(make_view(&buffer[start..end], 0, start as u32));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buffer & offsets here is guaranteed to come from trusted/correct data?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Both come from the private builders here, and the offsets are recorded from the same buffer that build() consumes. Invalid ranges would panic on buffer[start..end] before reaching new_unchecked, so the required invariants are guaranteed.

@Jefffrey
Jefffrey merged commit 1535dc4 into apache:main Aug 22, 2026
19 checks passed
@Jefffrey

Copy link
Copy Markdown
Contributor

thanks @cakeni

Jefffrey pushed a commit that referenced this pull request Aug 24, 2026
…10814)

Fixes the parquet-variant-compute compilation failure introduced when
#10708 was merged after #10640.

BinaryViewArray::new_unchecked now expects Arc<[Buffer]>, but the call
added by #10640 still passed Vec<Buffer>. This converts the newly
constructed buffer vector into the required shared slice.

Verified with:

- cargo fmt --all -- --check
- cargo check -p parquet-variant-compute --all-targets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parquet-variant parquet-variant* crates performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Variant] Benchmark and optimize BinaryView construction in VariantArrayBuilder

2 participants